﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using WMSABL;
using ElectronicWMSA.Comm.ClassFiles;

namespace ElectronicWMSA.Warehouse
{
    public partial class List_AreaFrm : Form
    {
        #region
        private int _NID = 0;
        private string strWhere = "";
        PublicDataSet bll_CommonPub = new PublicDataSet();
        public List_AreaFrm()
        {
            InitializeComponent();
            this.strWhere = "";
            this.pageControlU.PageCurrent = 1;
            this.pageControlU.PageSize = 30;
            this.pageControlU.Bind();
        }
        #endregion

        #region 数据分页
        private int DBindU()
        {
            ElectronicWMSA.Comm.Forms.MsControls.PageData pageData = new ElectronicWMSA.Comm.Forms.MsControls.PageData();
            pageData.TableName = "PD_Area";
            pageData.PrimaryKey = "NID";
            pageData.OrderStr = "NID";
            pageData.PageIndex = this.pageControlU.PageCurrent;
            pageData.PageSize = this.pageControlU.PageSize;
            pageData.QueryCondition = strWhere;
            pageData.QueryFieldName = "*";

            this.pageControlU.bindingSource.DataSource = pageData.QueryDataTable().Tables[0];
            this.pageControlU.bindingNavigator.BindingSource = pageControlU.bindingSource;
            this.dataGridViewUserList.AutoGenerateColumns = false;
            this.dataGridViewUserList.DataSource = this.pageControlU.bindingSource;
            this.dataGridViewUserList.ClearSelection();
            this.dataGridViewUserList.CurrentCell = null;
            return pageData.TotalCount;
        }
        private int pageControlU_EventPaging(ElectronicWMSA.Comm.Forms.MsControls.EventPagingArg e)
        {
            return DBindU();
        }
        #endregion

        #region 查询
        private void btnUserSearch_Click(object sender, EventArgs e)
        {
            if (!SystemVariable.VaildationPermission("查询")) return;

            this.btnUClear_Click(sender, e);
        }
        #endregion

        #region  新增、保存
        private void btnUSave_Click(object sender, EventArgs e)
        {
            if (btnUSave.Text == "添加")
                this.Add();
            else
                this.UpdateSave();
        }

        private void btnNewUser_Click(object sender, EventArgs e)
        {
            if (!SystemVariable.VaildationPermission("新增")) return;
            this.btnUSave.Text = "添加";
            this.tabAnalysisList.SelectedIndex = 1;
            this._NID = 0;

            this.txtName.Text = "";
            this.txtNO.Text = "";
            this.txtEmail.Text = "";
            this.txtName.Enabled = true;
            this.txtName.Focus();
        }

        #region 添加
        public void Add()
        {
            if (!SystemVariable.VaildationPermission("新增")) return;

        }
        #endregion

        #region 修改
        private void UpdateSave()
        {
            if (!SystemVariable.VaildationPermission("编辑")) return;
            if (_NID > 0)
            {
            }
            else
            {

            }
        }
        #endregion

        #endregion

        #region 取消
        private void btnUClear_Click(object sender, EventArgs e)
        {
            this._NID = 0;
            this.txtName.Text = "";
            this.txtNO.Text = "";
            this.txtEmail.Text = "";
            this.txtName.Enabled = true;
            this.pageControlU.Bind();
        }
        #endregion

        #region 序号
        private void dataGridViewUserList_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(dataGridViewUserList.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridViewUserList.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
        }
        #endregion

        #region 事件
        private void dataGridViewUserList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                if (this.dataGridViewUserList.Rows.Count != 0)
                {
                    #region 获取单列详细信息
                    if (e.ColumnIndex != -1 && this.dataGridViewUserList.CurrentCell.ColumnIndex == 0)
                    {
                        this._NID = Convert.ToInt32(this.dataGridViewUserList.CurrentRow.Cells["NID"].Value.ToString());
                        
                    }
                    else
                    {
                        this._NID = 0;
                        this.txtName.Text = "";
                        this.txtNO.Text = "";
                        this.txtEmail.Text = "";
                        this.txtName.Enabled = true;
                    }
                    #endregion

                    #region 确认删除
                    if (e.ColumnIndex != -1 && this.dataGridViewUserList.CurrentCell.ColumnIndex == 1)
                    {
                       
                    }
                    #endregion
                }
            }
        }
        #endregion


        private void linkLabelClose_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPages();
        }

        private void linkLabellinkLabelCloseAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseAllTabPages();
        }

        private void linkLabelCloseElse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPageElse();
        }

        private void btnRetunList_Click(object sender, EventArgs e)
        {
            this.tabAnalysisList.SelectedIndex = 0;
        }

    }
}
